<template>
    <div>
    <el-form inline class="demo-form-inline">
    <el-row >
        <el-col :span="5">
            <el-form-item label="member_id">
                <el-input v-model="query.payload.memberId" placeholder="member_id" />
            </el-form-item>
        </el-col>
        <el-col :span="5">
            <el-form-item label="sku_id">
                <el-input v-model="query.payload.skuId" placeholder="sku_id" />
            </el-form-item>
        </el-col>
        <el-col :span="5">
            <el-form-item label="活动场次id">
                <el-input v-model="query.payload.sessionId" placeholder="活动场次id" />
            </el-form-item>
        </el-col>
        <el-col :span="5">
            <el-form-item label="订阅时间">
                <el-input v-model="query.payload.subcribeTime" placeholder="订阅时间" />
            </el-form-item>
        </el-col>
    </el-row>
    <el-row>
        <el-col :span="5">
            <el-form-item label="发送时间">
                <el-input v-model="query.payload.sendTime" placeholder="发送时间" />
            </el-form-item>
        </el-col>
        <el-col :span="5">
            <el-form-item label="通知方式[0-短信，1-邮件]">
                <el-input v-model="query.payload.noticeType" placeholder="通知方式[0-短信，1-邮件]" />
            </el-form-item>
        </el-col>
    </el-row>
    <el-row >
        <el-form-item label="创建时间">
            <el-date-picker
                    v-model="query.dateRange"
                    type="datetimerange"
                    range-separator="到"
                    start-placeholder="开始时间"
                    end-placeholder="结束时间"
            />
        </el-form-item>
        <el-form-item>
            <el-button type="primary" activity @click="querySmsSeckillSkuNotice">查询</el-button>
            <el-button type="warning" activity @click="reset">重置</el-button>
            <el-button type="success" @click="addSmsSeckillSkuNotice">新增</el-button>
        </el-form-item>
    </el-row>
    </el-form>
    <el-divider style="margin: 12px 0"/>
    <el-table ref="table" border v-loading="loading"  :data="data.tableData" header-cell-class-name="headerClass">
        <el-table-column align="center" type="index"  label="序号" width="100px" />
        <el-table-column align="center" prop="memberId" label="member_id" />
        <el-table-column align="center" prop="skuId" label="sku_id" />
        <el-table-column align="center" prop="sessionId" label="活动场次id" />
        <el-table-column align="center" prop="subcribeTime" label="订阅时间" />
        <el-table-column align="center" prop="sendTime" label="发送时间" />
        <el-table-column align="center" prop="noticeType" label="通知方式[0-短信，1-邮件]" />
        <el-table-column align="center" prop="updateTime" label="更新时间" >
            <template #default="scope">
                {{moment(scope.row.updateTime).format("yyyy-MM-DD HH:mm:ss")}}
            </template>
        </el-table-column>
        <el-table-column align="center" label="操作">
            <template #default="scope">
                <el-link title="修改" type="primary" @click="editSmsSeckillSkuNotice(scope.row.id)">
                    <el-icon :size="20">
                        <Edit />
                    </el-icon>
                    修改
                </el-link>
                &nbsp;
                <el-popconfirm title="删除？" @confirm="deleteSmsSeckillSkuNotice(scope.row.id)"  @cancel="">
                    <template #reference>
                        <el-link type="danger" title="删除">
                            <el-icon :size="20">
                                <Delete />
                            </el-icon>
                            删除
                        </el-link>
                    </template>
                </el-popconfirm>
            </template>
        </el-table-column>
</el-table>
<el-pagination
        style="display: flex;align-items:center;justify-content:center;"
        v-model:currentPage="query.currentPage"
        v-model:page-size="query.pageSize"
        :page-sizes="[10, 20, 30]"
        layout="total, sizes, prev, pager, next, jumper"
        :total="query.total"
        @size-change="querySmsSeckillSkuNotice"
        @current-change="querySmsSeckillSkuNotice"
/>
<ModSmsSeckillSkuNotice @close="modSmsSeckillSkuNotice.isOpen = false"  @reload="querySmsSeckillSkuNotice"
              ref="modSmsSeckillSkuNotice"
              :openType="transData.openType"
              :id="transData.id" />
</div>
</template>

<script setup>
    import ModSmsSeckillSkuNotice from '@/views/mall/sms/components/ModSmsSeckillSkuNotice.vue'
    import request from '@/utils/request.js'
    import { ElMessage } from 'element-plus'
    import {ref, reactive, onMounted} from 'vue'
    import moment from 'moment'
    let transData = reactive({})
    let modSmsSeckillSkuNotice = ref(null)
    let data = reactive({
        modRole:false,
        tableData:[],
        openType:"",
        id:"",
    });
    let loading = ref(true)
    let query = reactive({dateRange:[],payload:{}, currentPage:1,pageSize:10,total:0})
    onMounted(() => {
        querySmsSeckillSkuNotice()
    })
    function querySmsSeckillSkuNotice(){
        query.startTime = query.dateRange[0]
        query.endTime = query.dateRange[1]
        request.post("/api/smsSeckillSkuNotice/getSmsSeckillSkuNoticePage", query).then(resp => {
            data.tableData = resp.records
            query.total = resp.total
            loading.value = false
        })
    }

    function reset(){
        query.payload.memberId = ""
        query.payload.skuId = ""
        query.payload.sessionId = ""
        query.payload.subcribeTime = ""
        query.payload.sendTime = ""
        query.payload.noticeType = ""
        query.dateRange=[]
    }

    function addSmsSeckillSkuNotice(){
        transData.openType = "add"
        modSmsSeckillSkuNotice.value.isOpen = true
    }

    function deleteSmsSeckillSkuNotice(id){
        request.get(`/api/smsSeckillSkuNotice/delete/${id}`).then(resp => {
            querySmsSeckillSkuNotice()
            ElMessage({message: '删除成功！',openType: 'success'})
        });
    }

    function editSmsSeckillSkuNotice(id){
        transData.id = id
        transData.openType = "edit"
        modSmsSeckillSkuNotice.value.isOpen = true
    }

</script>
<style lang="css">

</style>


